<?php

namespace App\Listeners;

use App\Events\NewNotification;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Redis;

class NewNotificationEventListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  NewNotification  $event
     * @return void
     */
    public function handle(NewNotification $event)
    {
        // notification-1 发布用户1的通知
        $notification = $event->notification;
        $channel = 'notification-'.$notification->user_id;
        
        Redis::publish($channel, json_encode($notification));
        // dd($notification);
    }
}
